package com.maple.admin.misc.paging.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.maple.admin.misc.paging.dao.IPagingDAO;

@Repository
@Transactional
public class IPagingDAOImpl implements IPagingDAO {
	@Autowired
	SessionFactory sessionFactory;

	@Override
	public Integer countTableRows(Class<?> tableClazz) {
		// TODO Auto-generated method stub
		Session session;
		try {
			session = sessionFactory.getCurrentSession();
		} catch (HibernateException e) {
			// TODO: handle exception
			session = sessionFactory.openSession();
		}
		Criteria crit = session.createCriteria(tableClazz);
		crit.setCacheable(true);
		Integer rowsCount = crit.list().size();
		return rowsCount;
	}
	
	
}
